package com.api.gbhg.luoao.flow;

import com.api.gbhg.liwenjun.GBHGConstant;
import com.api.gbhg.liwenjun.VersionFlowUtil;
import com.api.gbhg.luoao.tool.ToolCURD;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 海关离退休人员工资津贴补贴经费同步
 */
public class RetirementAllowance implements Action {

    private static final Logger logger = LoggerFactory.getLogger(RetirementAllowance.class);

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String workflowid = requestInfo.getWorkflowid();

        RecordSet recordSet1 = ToolCURD.selectDetailnanlist(requestInfo, 1);
        String flowTableName = VersionFlowUtil.getFlowTableName(workflowid);
        double total = 0;
        while (recordSet1.next()) {
            total = total + recordSet1.getDouble("hj");
        }
        try {
            RecordSet recordSet = new RecordSet();
            recordSet.executeUpdate("UPDATE " + flowTableName + " SET ltxryjfhj = " + total + " WHERE  requestId = " + requestid);
        } catch (Exception e) {
            e.printStackTrace();
        }


        Map<String, String> stringStringMap = new HashMap<>();
        stringStringMap.put("xmmin", "xmmc");
        stringStringMap.put("yszje", "ltxryjfhj");
        boolean b = VersionFlowUtil.sysDataToVersion(requestid, workflowid, GBHGConstant.FlowVersionTableEnum.uf_txrygzjtbtbb, stringStringMap);
        if (b) {
            return SUCCESS;
        } else {
            requestInfo.getRequestManager().setMessagecontent("数据同步失败!");
            requestInfo.getRequestManager().setMessageid("7763");
            return FAILURE_AND_CONTINUE;
        }
    }


}
